//
//  UtilsMacros.h
//  GLGW_Shoping
//
//  Created by yang on 2018/11/8.
//  Copyright © 2018年 yang. All rights reserved.
//

#ifndef UtilsMacros_h
#define UtilsMacros_h

//获取系统对象
#define kApplication        [UIApplication sharedApplication]
#define kAppWindow          [UIApplication sharedApplication].delegate.window
#define kAppDelegate        ((AppDelegate *)[[UIApplication sharedApplication] delegate])
#define kRootViewController [UIApplication sharedApplication].delegate.window.rootViewController
#define kUserDefaults       [NSUserDefaults standardUserDefaults]
#define kNotificationCenter [NSNotificationCenter defaultCenter]
//键盘⌨️
#define kKeyboardEndEditing [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
//系统版本
//判断是在iOS11之前
#ifndef kiOS11Before
#define kiOS11Before (kSystemVersion < 11)
#endif

#define WS(weakSelf)  __weak __typeof(&*self)weakSelf = self;

#define kIsiOS11   (float)kSystemVersion >= 11.0?YES:NO

#define kIsiOS10   (float)kSystemVersion >= 10.0?YES:NO
#define IOS10_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0)
#define IOS9_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0)
#define IOS8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
#define IOS7_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
//强弱引用
#define kWeakSelf(type)  __weak typeof(type) weak##type = type;
#define kStrongSelf(type) __strong typeof(type) type = weak##type;
//当前APP版本
#define kVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
//-------------------打印日志-------------------------
#if 1
#define DLog(format, ... ) printf("class: <%s:(%d) > method: %s \n%s\n", [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, [[NSString stringWithFormat:(format), ##__VA_ARGS__] UTF8String] );
#else
#define DLog(...)
#endif
//随机颜色
#define kBuleColor @"#002be3"
#define random(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)/255.0]
#define kRandomColor random(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))
//字体
#define BOLDSYSTEMFONT(FONTSIZE)[UIFont boldSystemFontOfSize:FONTSIZE]
#define SYSTEMFONT(FONTSIZE)    [UIFont systemFontOfSize:FONTSIZE]
#define FONT(NAME, FONTSIZE)    [UIFont fontWithName:(NAME) size:(FONTSIZE)]
//发送通知
#define KPostNotification(name,obj) [[NSNotificationCenter defaultCenter] postNotificationName:name object:obj];
//获取屏幕宽高
#define KScreenWidth  [[UIScreen mainScreen] bounds].size.width
#define KScreenHeight [[UIScreen mainScreen] bounds].size.height
#define kScreen_Bounds [UIScreen mainScreen].bounds
//适配iPhonex
#define iPhoneX (KScreenHeight == 812.0f || KScreenHeight == 896.0f)?YES : NO
#define NAVIHEIGHT (iPhoneX ? 88 :64)
#define TABBARHEIGHT (iPhoneX ? 83 : 49)

#define iPhone4 (KScreenWidth == 320.f && KScreenHeight == 480.f ? YES : NO)
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)
//比例
#define kWidthProportion_In_iPhoneTriploid(__Width) (KScreenWidth * ((__Width) / 375.0))
#define kHeightProportion_In_iPhoneTriploid(__Height) (KScreenWidth * ((__Height) /  375.0))

#define kY_With_View(__View, __Y) (__View.y + __View.height + kHeightProportion_In_iPhoneTriploid(__Y))
#define kX_With_View(__View, __X) (__View.x + __View.width + kWidthProportion_In_iPhoneTriploid(__X))

//#define AdaptNaviHeight      iPhoneX ? 24 : 0
//#define AdaptTabHeight       (iPhoneX ? 34 : 0)
#endif /* UtilsMacros_h */
